/**
 * 主题配置 - 现代化风格主题系统
 */

// 主题类型定义
export type ThemeStyle = 'blue' | 'purple' | 'green' | 'orange' | 'pink';
export type ThemeKey = `${ThemeStyle}-light`;

// 5种炫酷科技风主题配置
export const themeStyles = {
  blue: {
    name: '电光蓝·未来科技',
    icon: '⚡',
    key: 'blue-light',
  },
  purple: {
    name: '星空紫·神秘幻彩',
    icon: '🌌',
    key: 'purple-light',
  },
  green: {
    name: '矩阵绿·赛博朋克',
    icon: '🔢',
    key: 'green-light',
  },
  orange: {
    name: '熔岩红·烈焰战士',
    icon: '🔥',
    key: 'orange-light',
  },
  pink: {
    name: '樱花粉·浪漫梦幻',
    icon: '🌸',
    key: 'pink-light',
  },
} as const;

// 主题颜色配置
const themeColors: Record<ThemeKey, { primary: string; primaryHover: string }> = {
  'blue-light': { primary: '#4A90E2', primaryHover: '#357ABD' },
  'purple-light': { primary: '#8B7ED8', primaryHover: '#7B6BC0' },
  'green-light': { primary: '#52C41A', primaryHover: '#389E0D' },
  'orange-light': { primary: '#FA8C16', primaryHover: '#D46B08' },
  'pink-light': { primary: '#EB2F96', primaryHover: '#C41D7F' },
};

/**
 * 获取当前主题配置
 */
export const getCurrentTheme = (themeKey: ThemeKey) => {
  const colors = themeColors[themeKey];
  return {
    token: {
      colorPrimary: colors.primary,
      colorPrimaryHover: colors.primaryHover,
    },
  };
};

/**
 * 应用主题到文档根元素
 */
export const applyTheme = (themeKey: ThemeKey) => {
  const root = document.documentElement;
  root.setAttribute('data-theme', themeKey);

  // 保存主题设置到本地存储
  localStorage.setItem('theme-key', themeKey);
  localStorage.setItem('theme-mode', 'light');
};

/**
 * 获取保存的主题设置
 */
export const getSavedTheme = (): ThemeKey => {
  const savedThemeKey = localStorage.getItem('theme-key') as ThemeKey;
  if (savedThemeKey && themeColors[savedThemeKey]) {
    return savedThemeKey;
  }

  return 'blue-light'; // 默认主题
};

/**
 * 获取主题样式信息
 */
export const getThemeStyleInfo = (themeKey: ThemeKey) => {
  const [style] = themeKey.split('-') as [ThemeStyle, string];
  return {
    style,
    info: themeStyles[style],
  };
};

/**
 * 获取所有可用的主题列表
 */
export const getAvailableThemes = (): ThemeKey[] => {
  return Object.keys(themeColors) as ThemeKey[];
};
